from app.chess import db


class ChessMatch(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    red_player = db.Column(db.Integer, nullable=False)
    black_player = db.Column(db.Integer, nullable=False)
    token = db.Column(db.String(64), nullable=False, unique=True)
    state = db.Column(db.String(8))    # OnGoing, Finish
    result = db.Column(db.String(256))  #
    param = db.Column(db.String(1024))  #
    create_time = db.Column(db.DateTime, nullable=False)


class ChessGameProcess(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    match_id = db.Column(db.Integer, nullable=False)
    seq = db.Column(db.Integer, nullable=False)
    move = db.Column(db.String(64), nullable=False)
    dead_piece = db.Column(db.String(8))
    status = db.Column(db.Text, nullable=False)
    update_time = db.Column(db.DateTime, nullable=False)


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), nullable=False, unique=True)
    password = db.Column(db.String(192), nullable=False)
    create_time = db.Column(db.DateTime, nullable=False)

    def get_id(self):
        return self.id

    @staticmethod
    def is_active():
        return True

    @property
    def is_authenticated(self):
        return True


# Todo: 这个表要改名为 GameDistrictUser
class GameDistrict(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    uid = db.Column(db.Integer, nullable=False, unique=True)
    username = db.Column(db.String(64), nullable=False)
    player = db.Column(db.SmallInteger, nullable=False)  # 0 表示红方， 1 表示黑方
    state = db.Column(db.String(32), nullable=False)  # Pending, OnChess
    match_id = db.Column(db.Integer)
    param = db.Column(db.String(1024))   # 参数
    # match_token = db.Column(db.String(64), nullable=False)
    update_time = db.Column(db.DateTime, nullable=False)




